package com.mentalhealth.diary.common;

import java.io.Serializable;

/**
 * 统一响应结果类
 * 用于封装API接口返回数据
 */
public class R<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    
    /**
     * 响应状态码：0表示成功，非0表示失败
     */
    private int code;
    
    /**
     * 响应消息
     */
    private String msg;
    
    /**
     * 响应数据
     */
    private T data;
    
    /**
     * 构造方法
     */
    public R() {
    }
    
    public R(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    
    /**
     * 成功响应
     */
    public static <T> R<T> success(T data) {
        return new R<>(0, "success", data);
    }
    
    public static <T> R<T> success() {
        return new R<>(0, "success", null);
    }
    
    /**
     * 失败响应
     */
    public static <T> R<T> error(String msg) {
        return new R<>(500, msg, null);
    }
    
    public static <T> R<T> error(int code, String msg) {
        return new R<>(code, msg, null);
    }
    
    // Getters and Setters
    public int getCode() {
        return code;
    }
    
    public void setCode(int code) {
        this.code = code;
    }
    
    public String getMsg() {
        return msg;
    }
    
    public void setMsg(String msg) {
        this.msg = msg;
    }
    
    public T getData() {
        return data;
    }
    
    public void setData(T data) {
        this.data = data;
    }
}